using UnityEngine;
using System.Collections;

public class monsterSpawnerClass : MonoBehaviour {
	
	public float r;
	private float randomAngle;
	
	//public GameObject monster;
	
	public Transform objectToSpawn;
	
	private globalVarsClass gv;
	//private int mobCount = 1;
	
	//public float delay = 0;
	public bool gameStopped = false;
	
	// Use this for initialization
	private void Awake()
   	{
    	gv = GameObject.Find("GlobalVariables").GetComponent<globalVarsClass>();
  	}
	/*public void setPause(bool pause){
		if (pause){
			gameStopped = true;
		}else{
			gameStopped = false;
		}
	}*/
			
	// Use this for initialization
	void Start () {
		
		//gv.MobCount = mobCount;
		
		float height = 2 * Camera.main.orthographicSize;
  		float width = height * Camera.main.aspect;
		
		r = Mathf.Sqrt((height/2)*(height/2) + (width/2)*(width/2));
		
		randomAngle = Random.Range(0, 360);
		
		//monster.gameObject.transform.position = new Vector3(r * Mathf.Sin(randomAngle), r * Mathf.Cos(randomAngle), -1);
	}
	
	public void spawn(OTSprite objectToSpawn){
		if(objectToSpawn == null) return;
		
		randomAngle = Mathf.Deg2Rad * Random.Range(0.0f, 360.0f);
		
		if (gv.MobCount < 50) {
			Vector2 pos = new Vector2(r * Mathf.Sin(randomAngle), r * Mathf.Cos(randomAngle));
			OTSprite nEnemy = (Instantiate(objectToSpawn.gameObject) as GameObject).GetComponent<OTSprite>();
	       
	        nEnemy.position = pos;
			//nEnemy.rotation = gun.rotation;
			
			
			//OTSprite mob = (Instantiate(objectToSpawn, objectToSpawn.position, Quaternion.identity) as Transform).GetComponent<OTSprite>();
			//mob.position = pos;
			
			gv.MobList.Add(nEnemy);
			
			
			gv.MobCount++;
		}	
	}
	
	// Update is called once per frame
	void Update () {
	
		//delay -= Time.deltaTime;
		
		//if(delay > 0) return;
		//delay = 0.5f;
		
		//if(objectToSpawn == null) return;
		
		/*randomAngle = Mathf.Deg2Rad * Random.Range(0.0f, 360.0f);
		
		if (gv.MobCount < 50) {
			Vector2 pos = new Vector2(r * Mathf.Sin(randomAngle), r * Mathf.Cos(randomAngle));
			//Transform obj = Instantiate(objectToSpawn, objectToSpawn.position, Quaternion.identity) as Transform;
			OTSprite mob = (Instantiate(objectToSpawn, objectToSpawn.position, Quaternion.identity) as Transform).GetComponent<OTSprite>();
			mob.position = pos;
			
			gv.MobList.Add(mob);
			
			gv.MobCount++;
		}*/
	}
}
